package com.eshop.modules.quartz.utils;

import org.slf4j.LoggerFactory;
import org.springframework.util.ReflectionUtils;
import org.apache.commons.lang3.StringUtils;
import com.eshop.utils.SpringContextHolder;
import java.lang.reflect.Method;
import org.slf4j.Logger;
import java.util.concurrent.Callable;

public class QuartzRunnable implements Callable
{
    private static final Logger log;
    private Object target;
    private Method method;
    private String params;
    
    QuartzRunnable(final String beanName, final String methodName, final String params) throws NoSuchMethodException, SecurityException {
        this.target = SpringContextHolder.getBean(beanName);
        this.params = params;
        if (StringUtils.isNotBlank((CharSequence)params)) {
            this.method = this.target.getClass().getDeclaredMethod(methodName, String.class);
        }
        else {
            this.method = this.target.getClass().getDeclaredMethod(methodName, (Class<?>[])new Class[0]);
        }
    }
    
    @Override
    public Object call() throws Exception {
        ReflectionUtils.makeAccessible(this.method);
        if (StringUtils.isNotBlank((CharSequence)this.params)) {
            this.method.invoke(this.target, this.params);
        }
        else {
            this.method.invoke(this.target, new Object[0]);
        }
        return null;
    }
    
    static {
        log = LoggerFactory.getLogger((Class)QuartzRunnable.class);
    }
}
